package org.lease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.lease.mapper.SystemUserMapper;
import org.lease.model.dto.SystemUserItemDTO;
import org.lease.model.entity.SystemUser;
import org.lease.model.query.SystemUserPageQuery;
import org.lease.service.SystemUserService;
import org.springframework.stereotype.Service;

@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements SystemUserService {
    // 查：根据用户名查询员工
    @Override
    public SystemUser getByUsername(String username) {
        LambdaQueryWrapper<SystemUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SystemUser::getUsername, username);
        return this.getOne(wrapper);
    }

    // 分页条件查询员工员工
    @Override
    public IPage<SystemUserItemDTO> pageQuery(SystemUserPageQuery query) {
        Page<SystemUserItemDTO> page = new Page<>(query.getCurrent(), query.getSize());
        return baseMapper.pageQuery(page, query);
    }

    // 校验用户名是否可用
    @Override
    public boolean isUserNameAvailable(String username) {
        SystemUser user = this.getByUsername(username);
        return user == null;
    }
}
